home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / jmod310.zip / JMODEM.H < prev    next >
Text File  |  1991-11-30  |  25KB  |  333 lines

  1. /****************************************************************************/
  2. /*   FILE JMODEM.H                                                          */
  3. /*   Created 11-JAN-1990                Richard B. Johnson                  */
  4. /*                                      405 Broughton Drive                 */
  5. /*                                      Beverly, Massachusetts 01915        */
  6. /*                                      BBS (508) 922-3166                  */
  7. /*                                                                          */
  8. /*    This program requires about 67k of free RAM to execute properly.      */
  9. /*    If you have 66k or less, it will execute, but the screens will        */
  10. /*    not be written or replaced properly. If you have only 64k, the        */
  11. /*    program will exit with an error message.                              */
  12. /*                                                                          */
  13. /*    Revision History:                                                     */
  14. /*    V3.00   Beta test                  11-FEB-1990   Richard B. Johnson   */
  15. /*    V3.01   First release              18-FEB-1990   Richard B. Johnson   */
  16. /*    V3.02   Revised                    19-FEB-1990   Richard B. Johnson   */
  17. /*                                                                          */
  18. /*      (1)   A bug in MicroSoft _calloc()  allocates overlapping           */
  19. /*            buffers so data files were getting corrupted. I had           */
  20. /*            used both _calloc() and _malloc() at the same time and        */
  21. /*            they didn't like it. I changed the memory allocation          */
  22. /*            to _malloc() only and it seems to work okay.                  */
  23. /*                                                                          */
  24. /*      (2)   While debugging, I found some structures I didn't need and    */
  25. /*            removed them. Changed some code to accommodate.               */
  26. /*                                                                          */
  27. /*      (3)   Added a file-size during downloads.                           */
  28. /*                                                                          */
  29. /*      (4)   Changed code in the data encoding (compression) routine       */
  30. /*            in an attempt to speed it up.                                 */
  31. /*                                                                          */
  32. /*    V3.03   Revised                   20-FEB-1990  Richard B. Johnson     */
  33. /*                                                                          */
  34. /*      (5)   Fixed bug in compression routine where the loop wasn't        */
  35. /*            terminating properly, adding random characters. Bug was       */
  36. /*            created during V3.02 change.                                  */
  37. /*                                                                          */
  38. /*    V3.04   Revised                   27-FEB-1990  Richard B. Johnson     */
  39. /*                                                                          */
  40. /*      (1)   Modified the block-size routine and the receive-block         */
  41. /*            routine in an attempt to improve the noise immunity.          */
  42. /*            Does not abort even if you whistle into the telephone         */
  43. /*            during uploads and downloads. Waits 5 seconds to clear        */
  44. /*            the interrupt buffer when a bad block-size is received.       */
  45. /*                                                                          */
  46. /*      (2)   Added a 1/2 second wait for modem status when opening         */
  47. /*            channel. This might accommodate slow modems response to       */
  48. /*            RTS.                                                          */
  49. /*                                                                          */
  50. /*    V3.05   Revised                   22-MAR-1990  Richard B. Johnson     */
  51. /*                                                                          */
  52. /*      (1)   Removed _sprintf() runtime library calls to shorten           */
  53. /*            the code. Saved about 4k.                                     */
  54. /*                                                                          */
  55. /*      (2)   Removed extra spaces in the signon-logo to shorten            */
  56. /*            the program size.                                             */
  57. /*                                                                          */
  58. /*      (3)   Changed the method of creating a fixed-length string          */
  59. /*            for both the block size and cps numbers which saved about     */
  60. /*            800 bytes of program size.                                    */
  61. /*                                                                          */
  62. /*      (4)   Changed numerous array indexes in JMODEM_F.C to pointers      */
  63. /*            to reduce code size. Saved a few hundred bytes and should     */
  64. /*            improve speed of screen output.                               */
  65. /*                                                                          */
  66. /*      (5)   Created a local _puts() routine which saved over 6k from the  */
  67. /*            MicroSoft C runtime library version. (JMODEM_F.C)             */
  68. /*                                                                          */
  69. /*    V3.06   Revised                   07-APR-1990  Richard B. Johnson     */
  70. /*                                                                          */
  71. /*      (1)   Put the filename text into the syst structure as a pointer    */
  72. /*            to char. This allowed me to save 56 bytes of code and now     */
  73. /*            only two parameters are passed to the _screen() function.     */
  74. /*                                                                          */
  75. /*      (2)   Modified the syst structure and supporting code.              */
  76. /*                                                                          */
  77. /*      (3)   Moved all external data and functions to the JMODEM.H file.   */
  78. /*                                                                          */
  79. /*      (4)   Moved _disp() "usage" module to JMODEM_F.C                    */
  80. /*                                                                          */
  81. /*      (5)   Changed arrays in JMODEM_B.C to pointers to reduce code-      */
  82. /*            size. Eliminated _strcpy() from the command-line parsing      */
  83. /*            routines. Brought the code-size to less than 12,000 bytes.    */
  84. /*                                                                          */
  85. /*      (6)   Reduced the code-size in the _encode(), _decode(), and        */
  86. /*            _crc() routines in JMODEM_D.C. Removed shifts to improve      */
  87. /*            speed and replaced the shifts with pointers for altering      */
  88. /*            portions of the strings.                                      */
  89. /*                                                                          */
  90. /*      (7)   Made a _cancel() routine in JMODEM_A.C to send ^Xes upon      */
  91. /*            abort.                                                        */
  92. /*                                                                          */
  93. /*      (8)   Removed the bit being set "OUT 1" via the modem-control       */
  94. /*            register in the "open" routine in JMODEM_E.C. This was        */
  95. /*            causing some internal modems to lock up as they use this      */
  96. /*            bit for something. "OUT 2" is used to enable IRQ on most      */
  97. /*            clone RS-232 boards and modems. The Heathkit HZ-100 boards    */
  98. /*            will probably not work anymore because they use "OUT 1".      */
  99. /*                                                                          */
  100. /*    V3.07   Revised                   03-MAY-1990  Richard B. Johnson     */
  101. /*                                                                          */
  102. /*      (1)   Rewrote code to remove the requirement for a file buffer.     */
  103. /*            This means that this buffer does not need to be allocated,    */
  104. /*            saving about 8k of RAM at run-time.  ( JMODEM_A.C )           */
  105. /*                                                                          */
  106. /*            Program now only requires 52k of free RAM to execute okay.    */
  107. /*                                                                          */
  108. /*      (2)   Changed the header file, JMODEM.H, and function calling       */
  109. /*            procedures to file_io() and screen() to allow variable-       */
  110. /*            length parameter-lists. This eliminates the requirement       */
  111. /*            to pass a NULL as a place-holder on procedures that don't     */
  112. /*            always require all possible parameters to be passed. This     */
  113. /*            saved about 50 bytes of code.                                 */
  114. /*                                                                          */
  115. /*      (3)   Changed the "Usage" prompt and code to reduce program size.   */
  116. /*            Saved about 60 bytes.                                         */
  117. /*                                                                          */
  118. /*      (4)   Changed keyboard break interrupt in JMODEM_E.C so it sets     */
  119. /*            the global timer to zero as well as setting the abort flag.   */
  120. /*                                                                          */
  121. /*    V3.08   Revised                   01-DEC-1990  Richard B. Johnson     */
  122. /*                                                                          */
  123. /*      (1)   Changed the code to compile without warning errors when       */
  124. /*            using Microsoft Version 6.0. They saw fit to change the       */
  125. /*            ANSI standards for declaring objects passed to functions.     */
  126. /*            The new "standards" were called to my attention by            */
  127. /*            Jeff Jevnisek who provided modified source.                   */
  128. /*                                                                          */
  129. /*      (2)   Changed the method of determining a memory allocation         */
  130. /*            failure. The code used to check for a NULL pointer returned   */
  131. /*            from _malloc() if memory was not available. Microsoft does    */
  132. /*            not allow NULL to be used for that anymore! Instead I have    */
  133. /*            to either use a cast or check for (!ptr). I chose the latter. */
  134. /*                                                                          */
  135. /*    V3.09   Revised                   27-JUN-1991  Richard B. Johnson     */
  136. /*                                                                          */
  137. /*      (1)   Changed a typo in the previous revision record that showed    */
  138. /*            the date to be 01-DEC-1991 when it should be 01-DEC-1990      */
  139. /*                                                                          */
  140. /*      (2)   Changed the method of checking the interrupt buffer pointer   */
  141. /*            in JMODEM_E.C so that only one compare and no arithmetic      */
  142. /*            has to be done. JMODEM now works at 38,400 baud with a        */
  143. /*            33 MHz '386 machine.                                          */
  144. /*                                                                          */
  145. /*      (3)   Added support for using any communications port address       */
  146. /*            and IRQ.                                                      */
  147. /*                                                                          */
  148. /*            JMODEM R(3F8:4) filename.typ                                  */
  149. /*            JMODEM R(2F8:3) filename.typ                                  */
  150. /*            JMODEM S(3F8:4) filename.typ                                  */
  151. /*            JMODEM S(2F8:3) filename.typ                                  */
  152. /*            JMODEM S(20E:7) filename.typ  ... etc.                        */
  153. /*                                                                          */
  154. /*    V3.10   Revised                   19-NOV-1991  Richard B. Johnson     */
  155. /*                                                                          */
  156. /*      (1)   Changed the memory allocation method. Used to allocate 4      */
  157. /*            buffers with 4 calls to _malloc(). Now I allocate one large   */
  158. /*            block and cut it up into 4 pieces. This is more efficient.    */
  159. /*                                                                          */
  160. /*      (2)   Called _malloc() directly without a separate allocate_mem()   */
  161. /*            routine because machine differences can be handled with       */
  162. /*            definitions for different compilers and platforms.            */
  163. /*                                                                          */
  164. /*      (3)   Moved the receive and timer interrupt service routines to     */
  165. /*            assembly-language modules in JMODEM_G.ASM                     */
  166. /*                                                                          */
  167. /*                                                                          */
  168. /****************************************************************************/
  169. /*                  Parameters that are specific to JMODEM                  */
  170. /****************************************************************************/
  171. #define VERS            "Version 3.10"      /* Version number               */
  172. #define _8K             0x2000              /* 8192 bytes                   */
  173. #define BLK_SIZ         0x200               /* Starting block size          */
  174. #define OVRHD           0x06                /* Private, JMODEM overhead     */
  175. #define DAT_LEN         (_8K + 0x400)       /* Data buffer length           */
  176. #define DAT_MAX         _8K                 /* Max block length             */
  177. #define ALC_MEM        (DAT_LEN * 4)       /* Four buffers to allocate     */
  178. #define OPEN_READ       0x01                /* Private OPEN file function   */
  179. #define CREATE          0x02                /* Private CREATE file function */
  180. #define WRITE           0x03                /* Private WRITE file function  */
  181. #define CLOSE           0x04                /* Private CLOSE file function  */
  182. #define DELETE          0x05                /* Private DELETE file function */
  183. #define READ            0x06                /* Private READ file function   */
  184. #define GET_CRC         0x00                /* Private Get CRC function     */
  185. #define SET_CRC         0x01                /* Private Set CRC function     */
  186. #define NORM            0x01                /* Private, show normal data    */
  187. #define COMP            0x02                /* Private, show compressed     */
  188. #define EOF_            0x04                /* Private, show end of file    */
  189. #define TIMOUT          0x5A                /* Timeout (ticks) for read     */
  190. #define EOT             0x04                /* "D" - 64                     */
  191. #define ACK             0x06                /* "F" - 64                     */
  192. #define NAK             0x15                /* "U" - 64                     */
  193. #define SYN             0x16                /* "V" - 64                     */
  194. #define CAN             0x18                /* "X" - 64                     */
  195. #define SCR_SGN         0x01                /* Signon screen                */
  196. #define SCR_BOX         0x02                /* Write box on the screen      */
  197. #define SCR_TXT         0x03                /* Write text to x/y address    */
  198. #define SCR_STA         0x04                /* Write status box             */
  199. #define SCR_FIL         0x05                /* Write open file box          */
  200. #define SCR_FOK         0x06                /* File open okay               */
  201. #define SCR_FNF         0x07                /* File not found               */
  202. #define SCR_FCR         0x08                /* Can't create the file        */
  203. #define SCR_FRN         0x09                /* Renamed the file             */
  204. #define SCR_SYS         0x0A                /* Show system parameters       */
  205. #define SCR_SYT         0x0B                /* Show trans synchronization   */
  206. #define SCR_SYR         0x0C                /* Show Receive synchronization */
  207. #define SCR_FLG         0x0D                /* Show status flag             */
  208. #define SCR_END         0x0E                /* Exit all screens             */
  209. #define JM_NRM          0x00                /* Normal exit                  */
  210. #define JM_FNF          0x01                /* File not found               */
  211. #define JM_REN          0x02                /* Can't rename the file        */
  212. #define JM_CRE          0x03                /* Can't create the file        */
  213. #define JM_MEM          0x04                /* No memory available          */
  214. #define JM_CAR          0x05                /* Modem carrier failed         */
  215. #define JM_SYN          0x06                /* Can't synchronize            */
  216. #define JM_ABT          0x07                /* Aborted                      */
  217. #define JM_CMD          0x08                /* Command-line error           */
  218. #define JM_TIM          0x09                /* Time-out                     */
  219. #define JM_FAT          0x0A                /* Fatal error                  */
  220. #define JM_MAX          0xFFFF              /* Maximum buffer space exceeded*/
  221. #define byte unsigned char                  /* Make code readable           */
  222. #define word unsigned short int             /* Make code readable           */
  223. #define ulong unsigned long int             /* Make code readable           */
  224. /****************************************************************************/
  225. /*                     Structures and templates                             */
  226. /****************************************************************************/
  227. typedef struct
  228.         {                                   /* Structure for JMODEM status  */
  229.         word  s_blk;                        /* Block being sent / received  */
  230.         word  s_len;                        /* Length of the block          */
  231.         ulong s_byt;                        /* Bytes so far                 */
  232.         word  s_cps;                        /* Speed, characters / second   */
  233.         byte  *s_sta;                       /* Pointer to current status    */
  234.         byte  *s_txt;                       /* Pointer to information text  */
  235.         } SYS;
  236.  
  237. typedef struct                             /* JMODEM block header structure */
  238.         {
  239.         word len;                          /* Block length                  */
  240.         byte blk_typ;                      /* Kind of block EOF, COMP, etc  */
  241.         byte blk_num;                      /* Block number (starts at 1 )   */
  242.         byte blk_dat;                      /* First data character          */
  243.         } JBUF;
  244.  
  245. /****************************************************************************/
  246. /*                   External function prototypes                           */
  247. /****************************************************************************/
  248. #ifdef SCREEN
  249.     extern void screen(short, SYS *);       /* Function (in SCREEN.H)       */
  250. #else
  251.     extern void screen(short,...);          /* Show variable length list    */
  252. #endif
  253.  
  254. extern word open_chan(                      /* Open communications channel  */
  255.                 word);                      /* Communications port number   */
  256. extern word close_chan(                     /* Close communications channel */
  257.                 word);                      /* Communications port number   */
  258. extern word read_chan(                      /* Read communications channel  */
  259.                 word,                       /* Bytes to read                */
  260.                 byte *);                    /* Pointer to the buffer        */
  261. extern word write_chan(                     /* Write communications channel */
  262.                 word,                       /* Bytes to write (send)        */
  263.                 byte *);                    /* Pointer to the buffer        */
  264. extern word send_blk(                       /* Send JMODEM block            */
  265.                 word,                       /* Block length                 */
  266.                 SYS *,                      /* Pointer to status structure  */
  267.                 byte *);                    /* Pointer to the data buffer   */
  268. extern word recv_blk(                       /* Receive JMODEM block         */
  269.                 word *,                     /* Pointer to the block length  */
  270.                 byte *);                    /* Pointer to the data buffer   */
  271. extern word encode(                         /* Compress the data            */
  272.                 word,                       /* Length of the input data     */
  273.                 byte *,                     /* Pointer to the input buffer  */
  274.                 byte *);                    /* Pointer to the output buffer */
  275. extern word decode(                         /* Expand compressed data       */
  276.                 word,                       /* Data length                  */
  277.                 byte *,                     /* Pointer to the input buffer  */
  278.                 byte *);                    /* Pointer to the output buffer */
  279. extern word calc_crc(                       /* Calculate CRC                */
  280.                 word,                       /* Function, GET or SET         */
  281.                 word,                       /* Length of the data buffer    */
  282.                 byte *);                    /* Pointer to the data buffer   */
  283.  
  284. #ifdef FILE_IO
  285.     extern word file_io(                    /* File I/O                     */
  286.                 word,                       /* Function code                */
  287.                 short *,                    /* Pointer to the file handle   */
  288.                 byte *,                     /* Pointer to the buffer        */
  289.                 word);                      /* Data buffer length           */
  290. #else
  291.     extern word file_io(                    /* File I/O                     */
  292.                 word,                       /* Function code                */
  293.                 short *,...);               /* Variable length param list   */
  294. #endif
  295.  
  296. extern byte *get_inp(                       /* Get input file-name          */
  297.                 word,                       /* Number of arguments          */
  298.                 char *[]);                  /* Pointer to list of pointers  */
  299. extern byte get_fun(                        /* Get function (S or R)        */
  300.                 word,                       /* Number of arguments          */
  301.                 char *[]);                  /* Pointer to command strings   */
  302. extern word get_port(                       /* Get port (1 - 4)             */
  303.                 word,                       /* Number of arguments          */
  304.                 char *[]);                  /* Pointer to command strings   */
  305. extern void disp(void);                     /* Display 'usage' message      */
  306. extern void flush (void);                   /* Flush the interrupt buffer   */
  307. extern void cancel(void);                   /* Send ^Xes to cancel transfer */
  308. extern word tx_sync(void);                  /* Synchronize during transmit  */
  309. extern word rx_sync(void);                  /* Synchronize during receive   */
  310. /****************************************************************************/
  311. /*                   Global variables and structures                        */
  312. /****************************************************************************/
  313. extern byte *int_buffer;                    /* pointer to interrupt buffer  */
  314. extern word user_abort;                     /* User abort flag              */
  315. extern word port;                           /* Port number                  */
  316. extern word timer;                          /* Global timer                 */
  317. extern byte abrt[];                         /* Six messages in JMODEM_F.C   */
  318. extern byte okay[];
  319. extern byte retry[];
  320. extern byte done[];
  321. extern byte flow[];
  322. extern byte malfail[];
  323. extern SYS syst;                            /* Structure in JMODEM_A.C      */
  324. /****************************************************************************/
  325. /*                         Preprocessor directives                          */
  326. /****************************************************************************/
  327. #pragma intrinsic (inp, outp)               /* Generate in-line code here   */
  328. #pragma intrinsic (_disable, _enable)
  329. #pragma intrinsic (memcpy, _rotl)
  330. #pragma check_stack(off)                   /* No checking between functions */
  331. /****************************************************************************/
  332. /*********************** E N D  OF  M O D U L E *****************************/
  333.